/*
LPsol_test.cpp
------------------------------------------------------------

Program test several LP solver implementations for Packing Covering problems.

*/

#include "GLPKSol.h"
#include "GKPCSol.h"
#include "cuGKPCSol.h"

#include <string>

int main(int argc, char **argv)
{
	// file name
	char *fileName;
	std::string method;

	// pointers to input
	matrix_type *A;
	real *c;
	real *b;
	dreal omega = 0.1;
	integer m,n;
	

	
 
	/* input from console: ex.: /a.out filename omega 
	input generated by inputGenerator.py -> default filename: inputData.dat
	*/
	if(argc<7)
	{
		std::cout << "usage: LPsol_test -input <file_name> -error <omega> -method <method>" << std::endl;
		exit(1);
	    //fileName ="inputData2000x2000b.dat";
		//omega = 0.1;
	}
	
	// process command-line arguments
	for(int i=1;i<argc;i++)
	{
		if(strcmp(argv[i],"-input")==0)
		{
			fileName = argv[i+1];
		}
		if(strcmp(argv[i],"-error")==0)
		{
			omega = (dreal) atof(argv[i+1]);
		}
		if(strcmp(argv[i],"-method")==0)
		{
			method = std::string(argv[i+1]);
		}
	}

       
	long nonZeros = getFileInput(fileName,&A,&b,&c,m,n);

	// primal and dual solution
	dreal *x = new dreal[m];
	dreal *y = new dreal[n];

	if(VERBOSE && n*m<300)
	{
		printMatrix(A,m,n);
		printVector(c,n);
		printVector(b,m);
	}

	// find 1+omega approximate solution
	if(method=="GKPC")
	{
	std::cout << "\n\n\n********************** Finding approximate solution ************************** " << std::endl;
	GKPCSol(A,b,c,x,y,m,n,omega);
	}
	else if(method=="GKPC-CUDA")
	{
	std::cout << "\n\n\n****************** Finding approximate solution on CUDA ********************** " << std::endl;
	cuGKPCSol(A,b,c,x,y,m,n,omega);
    }
	else if(method=="GLPK")
	{
	std::cout << "\n\n\n********************** Finding optimal solution ************************** " << std::endl;
	GLPKSol(A,b,c,x,y,m,n,0.0);
	}
	else
	{ 
	   std::cout << "available methods: GK-PC approximation scheme -- flag: GKPC\n \
	                                    CUDA GK-PC approximation scheme -- flag: GKPC-CUDA \n \
										GLPK simplex method             -- flag: GLPK" << std::endl;
	}

	if(VERBOSE && n*m<10)
	{
		std::cout << "primal-dual pair:" << std::endl;

		printVector(x,n);
		printVector(y,m);
	}

	

	return 1;
	
}